package com.example.dao.implDao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dao.TeacherInfoDao;
import com.example.mapper.TeacherMapper;
import com.example.pojo.EnrollInfo;
import com.example.pojo.TeacherInfo;
import com.example.pojo.pojoenum.Position;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TeacherInfoDaoImpl implements TeacherInfoDao {
    @Autowired
    private TeacherMapper teacherMapper;
    @Override
    public List<TeacherInfo> teacherInfoList() {
        List<TeacherInfo> teacherInfos = teacherMapper.selectList(null);
        teacherInfos.forEach(System.out::println);
        return teacherInfos;
    }

    @Override
    public IPage<TeacherInfo> teacherInfoListPage(int currentPage, int limit) {
        // 创建分页对象
        Page<TeacherInfo> page = new Page<>(currentPage, limit);
        return teacherMapper.selectPage(page, null);
    }

    @Override
    public IPage<TeacherInfo> getTeacherByName(int currentPage, int limit, String teacherName) {
        Page<TeacherInfo> teacherInfoPage = new Page<>(currentPage,limit);
        QueryWrapper<TeacherInfo> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.likeRight("teacher_name",teacherName);
        return teacherMapper.selectPage(teacherInfoPage, teacherQueryWrapper);
    }

    @Override
    public TeacherInfo getTeacherByName(String teacherName) {
        QueryWrapper<TeacherInfo> teacherInfoQueryWrapper = new QueryWrapper<>();
        teacherInfoQueryWrapper.eq("teacher_name",teacherName);
        return teacherMapper.selectOne(teacherInfoQueryWrapper);
    }

    @Override
    public int addTeacher(TeacherInfo teacherInfo) {
        return teacherMapper.insert(teacherInfo);
    }


    @Override
    public int deleteTeacherInfo(Long eid) {
        return teacherMapper.deleteById(eid);
    }

}
